<?php
/**
 * Cloud Carousel
 * http://www.professorcloud.com/mainsite/carousel.htm
 *
 * @author danidhsm
 *
 */
class cloudCarousel extends CI_Controls{

	/**
	 *
	 * Enter Array con solo el nombre de la imagen que se le pasará al control
	 * @var array
	 */
	public $images;


	public $xPos;
	public $yPos;
	public $speed;
	function __construct(){
		parent::__construct();
		$this->images=array();
		$this->xPos=320;
		$this->yPos=40;
		$this->speed=0.2;
	}

	function drawContent(){



		$div= new div();
		$div->atributos=$this->atributos;

			
		//creo la estructura

		$imagenes=$this->images;
		$nimagenes=count($imagenes);
		for($i=0;$i<$nimagenes;++$i){
			$img=new img();
			$img->att('id','img_'.$i);
			$img->att('class','cloudcarousel');
			$img->att('src',$imagenes[$i]);
			$div->addControl($img);
		}
		$left=new input();
		$left->type="button";
		$left->att('id',$this->att('id').'_left');
		$left->value="left";

		$right=new input();
		$right->type="button";
		$right->att('id',$this->att('id').'_right');
		$right->value="right";

		$div->addControl($left);
		$div->addControl($right);
		$this->cloudCarousel_script();
		return $div;

	}

	private function cloudCarousel_script(){

		$this->CI->dynamic_assets->add_js(base_url('js/vendor/cloud-carousel.1.0.5.min.js'));
		
		ob_start();
		?>
		<script>
		$(document).ready(function(){
			   
			// This initialises carousels on the container elements specified, in this case, carousel1.
			$('#<?php echo $this->att('id');?>').CloudCarousel(		
				{		
				  reflHeight: 56,
				  reflGap:2,
				  xRadius:230,
				  yRadius:50,
				  bringToFront:true,
				  minScale:0.5, 	
					xPos: <?php echo $this->xPos;?>,
					yPos: <?php echo $this->yPos;?>,
					buttonLeft: $("#<?php echo $this->att('id');?>_left"),
					buttonRight: $("#<?php echo $this->att('id');?>_right"),
					FPS:25,
					autoRotate: 'left',
					autoRotateDelay: 2400,
					speed:<?php echo $this->speed?>,
					altBox: $("#<?php echo $this->att('id');?>_alt-text"),
					titleBox: $("#<?php echo $this->att('id');?>_title-text")
				}
			);
		});
			
		</script>
​
		<?php
		
		$this->CI->dynamic_assets->add_code_js(ob_get_clean());
			
	}
}